<?php


namespace app\common\cachemodel;

use app\common\model\Recode;

/**
 * 本命预测商品模型
 * Class NatalGoods
 * @package app\common\cachemodel
 */
class NatalGoods
{
    /**
     * 获取本命预测商品信息
     * @param int $type 7本命报告完全版 11=>本命报告精简版
     * @return array|mixed
     * @throws \Exception
     */
    public function getGoods(int $type = 7)
    {
        return (new Goods())->GoodsTypeInfo($type);
    }

    /**
     * 获取下单界面本命预测商品信息
     * @param $uid
     * @param $rid
     * @return array
     * @throws \Exception
     */
    public function getDownOrderGoods($uid, $rid)
    {
        // 获取商品信息
        $goodsData = $this->getGoods();
        // 获取用户已解锁商品信息
        $recodeInfo = (new Recode())->getRecode(['id' => $rid, 'uid' => $uid]);
        $unlockReport = (new NatalReport())->getNatalReport2($recodeInfo);
        // $unlockReport = (new NatalReport())->getNatalReport($uid, $rid);

        $data = [];
        foreach ($goodsData as $k => $v)
        {
            $data[] = [
                'gid' => $v['id'],
                'name' => $v['name'],
                'or_price' => $v['or_prize'],
                'now_price' => $v['now_prize'],
                'is_unlock' => isset($unlockReport[$v['id']]) ? 1 : 0
            ];
        }

        return $data;
    }
}
